

export default function ({ $axios, store, redirect }) {
  $axios.onRequest(config => {
    config.headers[ 'Authorization' ] = 'Bearer ' + store.state.token;
    return config;
  });

  $axios.onError(error => {
    window.console.log(error);
    if (error.response) {
      switch (error.response.status) {
        case 401:
          redirect('/login');
          // router.replace({path: '/login', query: { redirect: router.currentRoute.fullPath }});
      }
    }
    return Promise.reject(error);
  })
}
